package com.example.demo.message;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.teaopenapi.models.Config;
import com.example.demo.constant.Constant;

public class ForSample {
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        // 工程代码泄露可能会导致AccessKey泄露，并威胁账号下所有资源的安全性。以下代码示例仅供参考，建议使用更安全的 STS 方式，更多鉴权访问方式请参见：https://help.aliyun.com/document_detail/378657.html

        Config config = new Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId(Constant.ACCESS_KEY_ID)
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret(Constant.ACCESS_KEY_SECRET);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        Client client = new Client(config);
        String phones = "15690676093,18595545451,15690676093,15690676093";
        String[] str = phones.split(",");
        for (String s : str) {
            //SMS_271485777  SMS_154950909
            SendSmsRequest sendSmsRequest = new SendSmsRequest()
                    .setSignName("阿里云短信测试")
                    .setTemplateCode("SMS_154950909")
                    .setPhoneNumbers(s)
                    .setTemplateParam("{\"code\":\"88888\"}");

            try {
                // 复制代码运行请自行打印 API 的返回值

                SendSmsResponse response = client.sendSms(sendSmsRequest);
                System.out.println(response.getBody().getCode());
                System.out.println(response.getBody().getMessage());
            } catch (TeaException error) {
                // 如有需要，请打印 error
                com.aliyun.teautil.Common.assertAsString(error.message);
            } catch (Exception _error) {
                TeaException error = new TeaException(_error.getMessage(), _error);
                // 如有需要，请打印 error
                com.aliyun.teautil.Common.assertAsString(error.message);
            }
        }
        /*//SMS_271485777  SMS_154950909
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("阿里云短信测试")
                .setTemplateCode("SMS_154950909")
                .setPhoneNumbers("18595545451")
                .setTemplateParam("{\"code\":\"88888\"}");

        try {
            // 复制代码运行请自行打印 API 的返回值

            SendSmsResponse response = client.sendSms(sendSmsRequest);
            System.out.println(response.getBody());
            System.out.println("短信发送成功");
        } catch (TeaException error) {
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要，请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }*/
    }
}
